from .base_model import BaseModel
from .school_year import SchoolYear
from django.db import models

class Semester(BaseModel):
    """学期模型"""
    FIRST_SEMESTER = 'first'
    SECOND_SEMESTER = 'second'
    SUMMER_SESSION = 'summer'

    SEMESTER_CHOICES = [
        (FIRST_SEMESTER, '第一学期'),
        (SECOND_SEMESTER, '第二学期'),
        (SUMMER_SESSION, '暑期课程'),
    ]

    school_year = models.ForeignKey(SchoolYear, on_delete=models.CASCADE, related_name='semesters', verbose_name="学年")
    name = models.CharField(max_length=20, choices=SEMESTER_CHOICES, verbose_name="学期名称")
    start_date = models.DateField(verbose_name="开始日期")
    end_date = models.DateField(verbose_name="结束日期")
    is_current = models.BooleanField(default=False, verbose_name="是否当前学期")

    def __str__(self):
        return f"{self.school_year} {self.get_name_display()}"

    class Meta:
        verbose_name = "学期"
        verbose_name_plural = "学期"
        unique_together = ('school_year', 'name')
        ordering = ['-start_date']